import '../model/result_model.dart';
import '../model/school_class_timetable_model.dart';
import '../utils/request.dart';

///学校班级课表接口
class SchoolClassTimetableApi {
  SchoolClassTimetableApi._();

  static final _singleton = SchoolClassTimetableApi._();

  factory SchoolClassTimetableApi() => _singleton;

  ///查询
  Future<SchoolClassTimetableQueryRes> query(
    final SchoolClassTimetableQueryReq req,
  ) =>
      request
          .getHandler(
            path: '/school/${req.schoolId}/timetable',
            params: req.toMap(),
          )
          .then((res) => SchoolClassTimetableQueryRes.fromModel(res));

  ///加载
  Future<SchoolClassTimetableInfoRes> info(final String id) => request
      .getHandler(path: '/school/timetable/$id')
      .then((res) => SchoolClassTimetableInfoRes.fromModel(res));

  ///新增
  Future<BaseModelRes> add(final SchoolClassTimetableAddReq req) =>
      request.postHandler(
        path: '/school/${req.schoolId}/timetable',
        data: req.toMap(),
      );

  ///修改
  Future<BaseModelRes> modify(final SchoolClassTimetableModifyReq req) =>
      request.putHandler(
        path: '/school/timetable/${req.id}',
        data: req.toMap(),
      );

  ///删除
  Future<BaseModelRes> delete(final String id) =>
      request.deleteHandler(path: '/school/timetable/$id');

  ///详情查询
  Future<SchoolClassTimetableDetailQueryRes> queryDetail(
    final SchoolClassTimetableDetailQueryReq req,
  ) =>
      request
          .getHandler(
            path: '/school/timetable/${req.classTimetableId}/detail',
            params: req.toMap(),
          )
          .then((res) => SchoolClassTimetableDetailQueryRes.fromModel(res));

  ///详情加载
  Future<SchoolClassTimetableDetailInfoRes> infoDetail(final String detailId) =>
      request
          .getHandler(path: '/school/timetable/detail/$detailId')
          .then((res) => SchoolClassTimetableDetailInfoRes.fromModel(res));

  ///详情新增
  Future<BaseModelRes> addDetail(final SchoolClassTimetableDetailAddReq req) =>
      request.postHandler(
        path: '/school/timetable/${req.classTimetableId}/detail',
        data: req.toMap(),
      );

  ///详情修改
  Future<BaseModelRes> modifyDetail(SchoolClassTimetableDetailModifyReq req) =>
      request.putHandler(
        path: '/school/timetable/detail/${req.id}',
        data: req.toMap(),
      );

  ///详情删除
  Future<BaseModelRes> deleteDetail(final String detailId) =>
      request.deleteHandler(path: '/school/timetable/detail/$detailId');
}

///学校班级课表接口单例
final schoolClassTimetableApi = SchoolClassTimetableApi();
